package com.huike.controller.statistics;
import com.huike.pojo.SubjectNum;
import com.huike.result.PageResult;
import com.huike.dto.ClientStatisticsDTO;
import com.huike.service.Statistics.ClientStatisticsService;
import com.huike.vo.ClientStatisticsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;


@RestController
@Api(tags = "客户统计相关接口")
@RequestMapping("/report")
@Slf4j
public class ClientStatisticsController {
    @Autowired
    private ClientStatisticsService clientStatisticsService;

    @ApiOperation("客户统计报表")
    @GetMapping("/contractStatisticsList")
    public PageResult contractStatisticsList(Integer pageNum,
                                             Integer pageSize,
                                             @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate beginCreateTime,
                                             @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate endCreateTime,
                                             String channel,
                                             String createBy) {
        //前面写成了Body接,改太麻烦了,我直接改了接收参数然后封装了对象
        ClientStatisticsDTO dto = ClientStatisticsDTO.builder()
                .pageNum(pageNum)
                .pageSize(pageSize)
                .beginCreateTime(beginCreateTime)
                .endCreateTime(endCreateTime)
                .channel(channel)
                .createBy(createBy)
                .build();

        return clientStatisticsService.clientStatisticsList(dto);
    }
    @ApiOperation("新增客户数折线图")
    @GetMapping("/contractStatistics/{beginCreateTime}/{endCreateTime}")
    public ClientStatisticsVO contractStatistics(@PathVariable String beginCreateTime,@PathVariable String endCreateTime){
        log.info("客户统计折线图==={},{}",beginCreateTime,endCreateTime);

        return clientStatisticsService.contractStatistics(beginCreateTime,endCreateTime);
    }

    @ApiOperation("学科客户分布")
    @GetMapping("/subjectStatistics/{beginCreateTime}/{endCreateTime}")
    public List<SubjectNum> subjectStatistics(@PathVariable String beginCreateTime, @PathVariable String endCreateTime){
        log.info("客户统计折线图==={},{}",beginCreateTime,endCreateTime);

        return clientStatisticsService.subjectStatistics(beginCreateTime,endCreateTime);
    }
}
